

        class Student {
    private String name;
    private int age;
    private String sex;

    public Student(String name, int age, String sex) {
        this.name = name;
        this.age = age;
        this.sex = sex;
    }

    public void show() {
        if (name.length() > 5) {
            throw new StudentException("姓名不合法，太长");
        }
        if (age < 10 || age > 30) {
            throw new StudentException("年龄不合法，年龄必须为 10~30 之间");
        }
        if (!"男".equals(sex) &&!"女".equals(sex)) {
            throw new StudentException("性别不合法，性别只能为男或女");
        }
        System.out.println("姓名: " + name + ", 年龄: " + age + ", 性别: " + sex);
    }
}

public class TestStudent {
    public static void main(String[] args) {
        Student student1 = new Student("张三", 15, "男");
        Student student2 = new Student("李四四", 25, "女");
        Student student3 = new Student("王五", 35, "其他");

        try {
            student1.show();
            student2.show();
            student3.show();
        } catch (StudentException e) {
            System.out.println(e.getMessage());
        }
    }
}